import openpyxl

def exract(filename):
    wb = openpyxl.load_workbook(filename)
    # sheetname = wb.get_sheet_names()
    ws = wb.active

    columnList1 = ['FF:FK','A:C','BZ:CA','W:X']
    result = []
    for x in columnList1:
        column1 = ws[x]
        for c in range(len(column1)):
            d = []
            for i in column1[c]:
                d.append(i.value)
            result.append(d)

    columnList2 = ['AB','K','CI','BM','DI']
    for x in columnList2:
        d = []
        column2 = ws[x]
        for c in range(len(column2)):
            d.append(column2[c].value)
        result.append(d)
    return result
    
def save(filename, result):
    wb = openpyxl.Workbook()
    ws = wb.active
    col = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R']
    for c in range(len(col)):
        for r in range(len(result[c])):
            ws.cell(row=r+1,column=c+1,value=result[c][r])
    wb.save(filename)

if __name__ == "__main__":
    old_filename = r"C:\Users\tujuan\Desktop\故障周报\8月故障周报\8.5-8.11\数据整理.xlsx"
    new_filename = r"C:\Users\tujuan\Desktop\故障周报\8月故障周报\8.5-8.11\8.5-8.11(整理1).xlsx"
    result = exract(old_filename)
    save(new_filename, result)
    print('Excel 创建成功！')